#include "KSideBar.h"

bool KSideBar::m_bRealTimeDotted = false;

KSideBar::KSideBar():
KControl(1)
{
	m_Image = NULL;
	m_bTransparent = false;
}

KSideBar::~KSideBar()
{
	if(m_Image != NULL)
		delete m_Image;
}

void KSideBar::SetImage(const WCHAR * szPath, COLORREF bkColor)
{
	if(szPath == NULL || lstrcmp(szPath, TEXT("")) == 0)
		return;

	if(m_Image == NULL)
		m_Image = new KImage();

	if(bkColor != -1)
		m_bTransparent = true;

	m_Image->Load(szPath);
}

void KSideBar::SetRealTimeDottedDrag(bool bRealTimeDotted)
{
	m_bRealTimeDotted = bRealTimeDotted;
}

bool KSideBar::Paint( KMessage & rMsg )
{
	if( m_Image != NULL )
	{
		HDC hdc = (HDC)rMsg.lParam;

		if(m_bTransparent)
			m_Image->TransparentBlt(hdc, m_Bounds.x, m_Bounds.y, m_Bounds.w, m_Bounds.h);
		else
			m_Image->StretchBlt(hdc, m_Bounds.x, m_Bounds.y, m_Bounds.w, m_Bounds.h);
	}

	return false;
}

bool KSideBar::LButtonDown( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, m_bRealTimeDotted, NULL, 0);
		SendMessage(rMsg.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(x, y));

		rMsg.sender = this;
		return true;
	}

	return false;
}